How can I and improve array matrix [0 1] by row and column constraints in Python